
class mySingletonLazy{

    private volatile static mySingletonLazy instance;

    //由于加锁的方法是static所以锁对象也要static
    private static final Object locker = new Object();

    public static mySingletonLazy getInstance() {
        //判断是否要加锁
        if (instance == null) {
            synchronized (locker) {
                //判断是否要实例化
                if (instance == null) {
                    instance = new mySingletonLazy();
                }
            }
        }
        return instance;
    }

    //防止直接实例化
    private mySingletonLazy() {
    }
}

public class Demo3 {
    public static void main(String[] args) {
    }
}
